package com.simplefaith.delisty;

import com.simplefaith.delisty.util.ActivityStackControlUtil;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.view.Window;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;

public class RoomActivity extends Activity {

	private LinearLayout roomLayout;

	private Button chatButton;
	private EditText chatText;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		ActivityStackControlUtil.add(this);
		// hide title
		this.requestWindowFeature(Window.FEATURE_NO_TITLE);
		// set view
		setContentView(R.layout.activity_room);

		roomLayout = (LinearLayout) findViewById(R.id.RoomLinearLayout);
		chatButton = (Button) findViewById(R.id.ChatButton);
		chatText = (EditText) findViewById(R.id.ChatText);

		chatButton.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				chat(chatText.getText().toString());
				chatText.setText("");
			}

		});
	}

	private void chat(String msg) {

		LinearLayout linearLayout = new LinearLayout(this);
		linearLayout.setOrientation(LinearLayout.HORIZONTAL);
		linearLayout.setLayoutParams(new LayoutParams(
				LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));

		TextView tv = new TextView(this);
		tv.setText(msg);

		linearLayout.addView(tv);

		roomLayout.addView(linearLayout);

	}

	protected void onDestroy() {
		super.onDestroy();
		ActivityStackControlUtil.remove(this);
	}
}
